home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CRIBBAGE.PAK / DIALOGS.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  175 lines

  1. //--------------------------------------------------------------------------
  2. // Turbo Cribbage -- Copyright (c) 1995, Borland International
  3. //--------------------------------------------------------------------------
  4. #ifndef DIALOGS_H
  5. #define DIALOGS_H
  6.  
  7. #include <owl/dialog.h>
  8. #include <owl/vbxctl.h>
  9. #include <owl/static.h>
  10. #include <owl/button.h>
  11. #include <owl/listbox.h>
  12. #include <owl/dc.h>
  13. #include <winsys/color.h>
  14.  
  15. #include "cards.h"
  16. #include "mhcd2001.h"
  17. #include "cribbage.rh"
  18.  
  19. // TCutDeckDialog -- a dialog which shows a deck of cards, and allows the
  20. // user to cut.
  21. //
  22. class TCutDeckDialog: public TDialog {
  23.   public:
  24.     TCutDeckDialog(TWindow* parent, TDeck& aDeck):
  25.       TDialog(parent, CUT_DIALOG), deck(aDeck) {
  26.         topcard = new TVbxMhCardDeck(this, 42, "", 193, 50, 71, 95);
  27.       selectedCard=-1;
  28.     }
  29.     void SetupWindow() {
  30.       TDialog::SetupWindow();
  31.       topcard->SetPropBackColor(TColor(192, 192, 192));
  32.       topcard->SetPropCardBack(ENUM(deck[0].backStyle));
  33.     }
  34.     void EvPaint() {
  35.       TDialog::EvPaint();
  36.       TClientDC dc(*this);
  37.       TMemoryDC memDC(dc);
  38.       TBitmap bitmap(_hInstance, CUT_BITMAP);
  39.       memDC.SelectObject(bitmap);
  40.       dc.BitBlt(40, 50, bitmap.Width(), bitmap.Height(), memDC, 0, 0, SRCCOPY);
  41.       topcard->Invalidate();
  42.     }
  43.     void EvLButtonDown(uint, TPoint& point) {
  44.       if (point.y>50 && point.y<145 && point.x>40 && point.y<193) {
  45.         selectedCard = (point.x - 40)/3;
  46.         CloseWindow();
  47.       }
  48.     }
  49.     int Execute() {
  50.       TDialog::Execute();
  51.       return selectedCard;
  52.     }
  53.     void Ignore() {}
  54.  
  55.   private:
  56.     TDeck& deck;
  57.     TVbxMhCardDeck *topcard;
  58.     int selectedCard;
  59.  
  60.   DECLARE_RESPONSE_TABLE(TCutDeckDialog);
  61. };
  62.  
  63. class TCutResultDialog: public TDialog {
  64.   public:
  65.     TCutResultDialog(TWindow* parent, const TCard& aPlayer, const TCard& aComputer):
  66.       TDialog(parent, CUT_RESULT_DIALOG),
  67.       player(aPlayer), computer(aComputer) {
  68.         c1 = new TVbxMhCardDeck(this, 1, "", 40, 50, 71, 95);
  69.         c2 = new TVbxMhCardDeck(this, 2, "", 180, 50, 71, 95);
  70.         msg = new TStatic(this, IDS_RESULT_MSG);
  71.     }
  72.     void SetupWindow() {
  73.       TDialog::SetupWindow();
  74.       c1->SetPropBackColor(TColor(192, 192, 192));
  75.       c2->SetPropBackColor(TColor(192, 192, 192));
  76.       c1->SetPropValue(ENUM(player.rank));
  77.       c1->SetPropSuit(ENUM(player.suit));
  78.       c2->SetPropValue(ENUM(computer.rank));
  79.       c2->SetPropSuit(ENUM(computer.suit));
  80.       if (player.rank==computer.rank)
  81.         msg->SetText("A tie.  Click OK to cut again.");
  82.       else
  83.         if (player.rank<computer.rank)
  84.           msg->SetText("You deal first.");
  85.         else
  86.           msg->SetText("Computer deals first.");
  87.     }
  88.  
  89.   private:
  90.     TVbxMhCardDeck *c1,*c2;
  91.     const TCard& player;
  92.     const TCard& computer;
  93.     TStatic *msg;
  94. };
  95.  
  96. class TGoDialog: public TDialog {
  97.   public:
  98.     TGoDialog(TWindow* parent, BOOL aCanPlay):
  99.       TDialog(parent, GO_DIALOG), canPlay(aCanPlay) {
  100.       button = new TButton(this, IDOK);
  101.     }
  102.     void SetupWindow() {
  103.       TDialog::SetupWindow();
  104.       if (canPlay)
  105.         SetDlgItemText(IDOK, "OK");
  106.       else
  107.         SetDlgItemText(IDOK, "Take 1 Point");
  108.     }
  109.  
  110.   private:
  111.     TButton *button;
  112.     BOOL canPlay;
  113. };
  114.  
  115. class TQuickPointsDialog: public TDialog {
  116.   public:
  117.     TQuickPointsDialog(TWindow* parent, const char *message, BOOL aPegging,
  118.                         int aActualPoints);
  119.     void SetupWindow();
  120.     int Execute() {
  121.       TDialog::Execute();
  122.       return points;
  123.     }
  124.     LRESULT EvCommand(uint id, HWND, uint) {
  125.       points = id-IDC_PUSHBUTTON0;
  126.  
  127.       if (points>actualPoints)
  128.         MessageBox("Perhaps you should count again.", "Cribbage", MB_OK);
  129.       else
  130.         Destroy(points);
  131.       return true;
  132.     }
  133.  
  134.   private:
  135.     int points;
  136.     const char *msgText;
  137.     TStatic *msg;
  138.     BOOL  pegging;
  139.     TButton *button[15];
  140.     int actualPoints;
  141. };
  142.  
  143. class TShowPointsDialog: public TDialog {
  144.   public:
  145.     enum ModeType { mtMissed, mtCrib, mtHand, mtPegging };
  146.  
  147.     TShowPointsDialog(TWindow* parent, ModeType aMode,
  148.                       int aPoints, int aMissedPoints,
  149.                       char **aDetail, int aDetailCount)
  150.     :
  151.       TDialog(parent, SHOW_POINTS_DIALOG), mode(aMode),
  152.       points(aPoints), detail(aDetail), detailCount(aDetailCount),
  153.       missedPoints(aMissedPoints)
  154.     {
  155.       msg = new TStatic(this, IDC_SHOW_POINTS_MESSAGE);
  156.       ok = new TButton(this, IDOK);
  157.       detailBtn = new TButton(this, CM_DETAIL);
  158.     }
  159.     void SetupWindow();
  160.     void ShowDetail();
  161.  
  162.   private:
  163.     TStatic *msg;
  164.     TButton *ok,*detailBtn;
  165.     TListBox *listbox;
  166.     char **detail;
  167.     int detailCount;
  168.     int points,missedPoints;
  169.     ModeType mode;
  170.  
  171.   DECLARE_RESPONSE_TABLE(TShowPointsDialog);
  172. };
  173.  
  174. #endif // DIALOGS_H
  175.